package com.showde.shoppingmall.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

public class ConformDialogUtils {

	private AlertDialog alertDialog;
	private Context context;

	private ConformDialogUtils(Context context) {
		this.context = context;
	}

	public static ConformDialogUtils getInstance(Context context) {
		return new ConformDialogUtils(context);
	}

	public interface DialogCallback {
		void onPositiveCall();
	}

	public void showConformDialog(String message, final DialogCallback callback) {
		alertDialog = new AlertDialog.Builder(context).setMessage(message)
				.setNegativeButton("取消", new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						alertDialog.dismiss();
					}
				}).setPositiveButton("确定", new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						callback.onPositiveCall();
						alertDialog.dismiss();
					}
				}).create();
		alertDialog.show();
	}

	public void showConformDialog(String title, String message,
			final DialogCallback callback) {
		alertDialog = new AlertDialog.Builder(context).setTitle(title)
				.setMessage(message)
				.setNegativeButton("取消", new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						alertDialog.dismiss();
					}
				}).setPositiveButton("确定", new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						callback.onPositiveCall();
						alertDialog.dismiss();
					}
				}).create();
		alertDialog.show();
	}

}
